package juc.day1;

import lombok.extern.slf4j.Slf4j;

/**
 * Description: 测试join
 *
 * @Autor: Rolin
 * datetime: 09-11-12:11
 */
@Slf4j
public class TestJoin {

    private static int r1 =0;
    private static int r2 =0;

    public static void main(String[] args) throws InterruptedException {
        test01();
    }

    private static void test01() throws InterruptedException {
        Thread thread1 = new Thread("Thread1"){
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                    log.debug("运行thread1线程。。。");
                    r1 = 10 ;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        Thread thread2 = new Thread("thread2"){
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    log.debug("运行thread2线程。。。");
                    r2 = 20 ;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        thread1.start();
        thread2.start();
        long start = System.currentTimeMillis();
        log.debug("thread1 join begin");
        thread1.join();
        log.debug("thread2 join begin");
        thread2.join();
        long end = System.currentTimeMillis();
        log.debug("time: {},r1: {},r2: {}",end-start,r1,r2);

    }
}
